<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    header {
      width: 375px;
      height: 60px;
      background-color: lightcoral;
      color: white;
      font-size: 20px;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
    }
    span {
      position: absolute;
      right: 20px;
      top: 50%;
      transform: translateY(-50%);
    }
  </style>
</head>
<body>
  <div id="app">
    <h2>props</h2>
    <p>count: {{ count }}</p>
    <button @click="count++">count++</button>
    <!-- 传递的时候，用连字符进行传递 -->
    <son :student-count="count"></son>
  </div>

  <script src="../vue3.js"></script>
  <script>
    // 单向数据流
    // props 因父组件的更新而变化，自然地将新的状态向下流往子组件
    // 子组件是不能修改props的值的

    const {createApp} = Vue;

    const Son = {
      // props: ["count"], // props的数组语法的接受

      props: {
        // 接受的时候，因为是对象的key，所以只能用小驼峰来接受
        studentCount: Number,
      }, // props的对象的语法，可以帮助我们检查传进来的数据的类型是否正确
      data() {
        return {
          sunCount: this.studentCount,
        }
      },
      computed: {
        doubleCount() {
          return this.studentCount * 2;
        }
      },
      template: `
        <div>这是子组件 - {{ studentCount }}</div>
        <button @click="studentCount++">studentCount++</button>
        <div>sunCount: {{ sunCount }}</div>
        <button @click="sunCount++">sunCount++</button>
        <div>doubleCount: {{ doubleCount }}</div>
      `
    }

    const app = createApp({
      data() {
        return {
          count: 10
        }
      },
      components: {
        Son
      }
    });

    app.mount("#app");
  </script>
</body>
</html>